package com.smile.config;

import cn.dev33.satoken.stp.StpInterface;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.*;

@Component    // 保证此类被 SpringBoot 扫描，完成 Sa-Token 的自定义权限验证扩展
@Configuration
public class StpInterfaceImpl implements StpInterface {


    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        Object o = redisTemplate.opsForValue().get(RedisConstant.PERMISSION_PREFIX + loginId);
        List<String> list = (List<String>) o;

        return list;
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        Object o = redisTemplate.opsForValue().get(RedisConstant.ROLE_PREFIX + loginId);

        return List.of(o.toString());
    }

}